package cn.com.joycode.nimble.core.utils;


import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.*;

@Slf4j
public class TestNbData {

    public static class NbData<K, V> extends AbstractMap<K, V> {

        @Getter
        private final HashMap<K, V> dataMap = new HashMap<>();

        @Override
        public V put(K key, V value) {
            return dataMap.put(key, value);
        }

        @Override
        public int size() {
            return dataMap.size();
        }

        @Override
        public boolean isEmpty() {
            return dataMap.isEmpty();
        }

        @Override
        public boolean containsKey(Object key) {
            return dataMap.containsKey(key);
        }

        @Override
        public boolean containsValue(Object value) {
            return dataMap.containsValue(value);
        }

        @Override
        public V get(Object key) {
            return dataMap.get(key);
        }

        @Override
        public V remove(Object key) {
            return dataMap.remove(key);
        }

        @Override
        public void putAll(Map<? extends K, ? extends V> m) {
            dataMap.putAll(m);
        }

        @Override
        public void clear() {
            dataMap.clear();
        }

        @Override
        public Set<K> keySet() {
            return dataMap.keySet();
        }

        @Override
        public Collection<V> values() {
            return dataMap.values();
        }

        @Override
        public Set<Entry<K, V>> entrySet() {
            return dataMap.entrySet();
        }
    }

    @Data
    public class NbApi<T> {

        private final String version = "1.0";

        private NbData<String, T> data = new NbData<>();
    }

    public void test() {
        NbApi<Object> nbApi = new NbApi<>();

        nbApi.getData().put("name", "max woods");

        nbApi.getData().put("time", LocalDateTime.now());

        log.info("string:{}", ObjectMapperUtil.toJsonString(nbApi));
    }
}
